/*
package com.itheima.dao;

import com.itheima.domain.Dept;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class DeptDaoImpl implements DeptDao {
    @Override
    public List<Dept> selectAllDept() {
        InputStream resource =null;
        List<Dept> list = null;
        try {
            resource = Resources.getResourceAsStream("DeptConfig.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            list = sqlSession.selectList("DeptMapper.selectAllDept");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list ;
    }

    @Override
    public void selectByDept() {
        InputStream resources =null;
        try {
             resources = Resources.getResourceAsStream("DeptConfig.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resources);
            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            Dept dept = sqlSession.selectOne("DeptMapper.selectByDept",10);
            System.out.println(dept.toString());
            sqlSession.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int insertDept(Dept dept) {
             InputStream resources =null;
        try {
             resources = Resources.getResourceAsStream("DeptConfig.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resources);
            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            int insert = sqlSession.insert("DeptMapper.insertDept",dept);
            sqlSession.close();
            return insert;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public int deleteDept(int deptno) {
        InputStream resource=null;
        try {
           resource= Resources.getResourceAsStream("DeptConfig.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            int  delete = sqlSession.delete("DeptMapper.deleteDept",deptno);
            if(resource!=null){
                resource.close();
            }
            if(sqlSession!=null){
                sqlSession.close();
            }
            sqlSession.close();
            return delete;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public int updateDept(Dept dept) {
        try {
            InputStream resources = Resources.getResourceAsStream("DeptConfig.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resources);
            SqlSession sqlSession = sqlSessionFactory.openSession(true);
            int update = sqlSession.update("DeptMapper.updateDept", dept);
            if (resources!=null){
                resources.close();
            }
            if(sqlSession!=null){
                sqlSession.close();
            }
            return update;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
*/
